#include "NamedPipe.hpp"
#include "log.hpp"

int main()
{
    Init init;
    Log log;
    log.Enable(CLASSFILE);
    //打开命名管道文件
    int fd=open(FIFO_NAME,O_RDONLY);
    if(fd<0)
    {
        log(FATAL,"error string:%s error code:%d",strerror(errno),errno);
    }
    //std::cout<<"server fifofile open"<<std::endl;
        log(INFO,"server fifofile open success !error string:%s error code:%d",strerror(errno),errno);
        log(WARNING,"server fifofile open success !error string:%s error code:%d",strerror(errno),errno);
        log(ERROR,"server fifofile open success !error string:%s error code:%d",strerror(errno),errno);
        log(FATAL,"server fifofile open success !error string:%s error code:%d",strerror(errno),errno);

    //开始通信
    while(true){
        char buffer[SIZE]={0};
       int n= read(fd,buffer,sizeof(buffer));
       if(n>0)
       {
        buffer[n]=0;
        std::cout<<"server get message:"<<buffer<<std::endl;
       }
       else if(n==0)
       {
        //std::cout<<"cline quit me too!"<<std::endl;
        log(INFO,"cline quit me too! error string:%s error code:%d",strerror(errno),errno);

        break;
       }
       else
       break;
    }

    //关闭管道文件
    close(fd);
    
    return 0;
}